Scheduler for UWP | ComponentOne
Features / Data Binding / Label Binding
In This Topic
    Label Binding
    In This Topic

    You can create your own collection of labels and bind them to the label data storage of the C1Scheduler control. For example, define a custom Label class or use the C1.C1Schedule.Label class.

    C#
    Copy Code
    public class MyLabel
     {
         public string Id { get; set; }
         public string Text { get; set; }
         public string Color { get; set; }
     }
    

    The Id and Index properties aren't required, but you should include either an Id (Guid/string) or an Index (int) identifier with each label for data storage purposes. This allows appointments to store label information between runs of the application.

    Label Color

    To specify label color, C1Scheduler uses string values such as “255,255,255,255” which represent the alpha, red, blue and green byte channels. This allows serialization and optimum storage space for all possible colors.

    You can create a collection of labels in code and bind it to the LabelStorage.DataSource property. You must also set the appropriate mappings for the ID, Text and Color properties.

    C#
    Copy Code
    // create list of labels
     List<MyLabel> Labels = new List<MyLabel>();
     Labels.Add(new MyLabel { Text = "Lime", Color = "255,164,196,0" });
     Labels.Add(new MyLabel { Text = "Green", Color = "255,96,169,23" });
     Labels.Add(new MyLabel { Text = "Teal", Color = "255,0,171,169" });
     Labels.Add(new MyLabel { Text = "Cyan", Color = "255,27,161,226" });
     Labels.Add(new MyLabel { Text = "Purple", Color = "255,170,0,255" });
     Labels.Add(new MyLabel { Text = "Pink", Color = "255,244,141,208" });
     Labels.Add(new MyLabel { Text = "Red", Color = "255,229,20,0" });
     Labels.Add(new MyLabel { Text = "Mango", Color = "255,240,150,9" });
     Labels.Add(new MyLabel { Text = "Yellow", Color = "255,227,200,0" });
     Labels.Add(new MyLabel { Text = "Olive", Color = "255,109,135,100" });
     Labels.Add(new MyLabel { Text = "Mauve", Color = "255,118,96,138" });
    
    // set label data storage and mappings
     c1Scheduler.DataStorage.LabelStorage.DataSource = Labels;
     c1Scheduler.DataStorage.LabelStorage.Mappings.TextMapping.MappingName = "Text";
     c1Scheduler.DataStorage.LabelStorage.Mappings.ColorMapping.MappingName = "Color";
     c1Scheduler.DataStorage.LabelStorage.Mappings.IdMapping.MappingName = "Id";
     Alternatively, you can also data bind in XAML. This snippet assumes you have a property named “Labels” in view model declared as a resource elsewhere in your project.
     <c1sched:C1Scheduler x:Name="c1Scheduler" AppointmentForeground="Black">
         <!-- Map Label storage -->
         <c1sched:NestedPropertySetter PropertyName="DataStorage.LabelStorage.DataSource"
                                       Value="{Binding Path = Labels, Source={StaticResource mainViewModel}}" />
         <c1sched:NestedPropertySetter PropertyName="DataStorage.LabelStorage.Mappings.TextMapping.MappingName"
                                       Value="Text"/>
         <c1sched:NestedPropertySetter PropertyName="DataStorage.LabelStorage.Mappings.ColorMapping.MappingName"
                                       Value="Color"/>
         <c1sched:NestedPropertySetter PropertyName="DataStorage.LabelStorage.Mappings.IdMapping.MappingName"
                                       Value="Id"/>
     </c1sched:C1Scheduler>